<%@ Page Title="Templates &raquo; ResourceBlender" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Templates.aspx.cs" Inherits="Templates" EnableEventValidation="false" ValidateRequest="false" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>

<asp:Content ID="contentHead" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="contentMain" ContentPlaceHolderID="cntMain" Runat="Server">
    <asp:SqlDataSource ID="dsMain" runat="server"
         ConnectionString="<%$ ConnectionStrings:Default %>"
         ProviderName="<%$ ConnectionStrings:Default.ProviderName %>"
         SelectCommand="SELECT id, name FROM templates">
    </asp:SqlDataSource>
    <asp:ScriptManager ID="scrMain" runat="server">
    </asp:ScriptManager>
    <asp:MultiView ID="mltMain" runat="server" ActiveViewIndex="1">
        <asp:View ID="viwManageTemplates" runat="server">
            <h1><asp:Label ID="lblManageTemplates" runat="server" Text="Manage Templates"></asp:Label></h1>
            <div class="breadcrumbs">
                <asp:HyperLink ID="lnkNavHome" runat="server" NavigateUrl="~/Default.aspx">ResourceBlender</asp:HyperLink> &gt; Templates
            </div>
            <asp:GridView ID="grdTemplates" runat="server" AllowPaging="True" 
                AllowSorting="True" AutoGenerateColumns="False" CssClass="nicetable" 
                DataSourceID="dsMain" OnRowCommand="grdTemplates_RowCommand" Width="100%">
                <PagerSettings PageButtonCount="7" />
                <Columns>
                    <asp:BoundField DataField="name" HeaderText="Name" 
                        SortExpression="name" />
                    <asp:TemplateField ItemStyle-CssClass="buttoncell" HeaderText="Edit">
                        <ItemTemplate>
                            <asp:ImageButton ID="btnEdit" runat="server" 
                                AlternateText='<%# "Edit " + Eval("name") %>' 
                                CommandArgument='<%# Eval("id") %>' CommandName="doedit" 
                                ImageUrl="~/images/edit.png" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ItemStyle-CssClass="buttoncell" HeaderText="Delete">
                        <ItemTemplate>
                            <asp:ImageButton ID="btnDelete" runat="server" 
                                AlternateText='<%# "Delete " + Eval("name") %>' 
                                CommandArgument='<%# Eval("id") %>' CommandName="confirmdelete" 
                                ImageUrl="~/images/delete.png" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <HeaderStyle CssClass="excelHead" />
                <AlternatingRowStyle CssClass="alt" />
                <EmptyDataTemplate>
                    <p>No templates have been added.</p>
                </EmptyDataTemplate>
            </asp:GridView>
            <asp:LinkButton ID="lnkNewTemplate" runat="server" CssClass="lnkAdd" 
                OnClick="lnkNewTemplate_Click">New Template</asp:LinkButton>
        </asp:View>
        <asp:View ID="pnlAddTemplate" runat="server">
            <div class="niceform">
                <h1><asp:Label ID="lblEditTemplates" runat="server" Text="New Template"></asp:Label></h1>
                <div class="breadcrumbs">
                    <asp:HyperLink ID="lnkNavHomeAdd" runat="server" NavigateUrl="~/Default.aspx">ResourceBlender</asp:HyperLink> &gt; <asp:HyperLink ID="lnkNavAddTemplates" runat="server" NavigateUrl="~/Templates.aspx">Templates</asp:HyperLink> &gt; <asp:Literal runat="server" ID="litNavAddAddTemplate" Text="Add Template"></asp:Literal>
                </div>
                <asp:Panel ID="pnlAddError" runat="server" Visible="false" CssClass="errorDiv">
                    <h1>Error</h1>
                    <asp:Label ID="lblAddError" runat="server" Text=""></asp:Label>
                </asp:Panel>
                <div class="formrow block">
                    <asp:Label ID="lblTemplateName" runat="server" AssociatedControlID="txtTemplateName" 
                        Text="Template Name"></asp:Label>
                    <asp:TextBox ID="txtTemplateName" runat="server" ValidationGroup="addtemplate"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="vldTemplateName" runat="server" 
                        ControlToValidate="txtTemplateName" Display="Dynamic" SetFocusOnError="true"
                        ErrorMessage="You must enter the template name" ValidationGroup="addtemplate"
                        CssClass="validationerror"></asp:RequiredFieldValidator>
                </div>
                <fieldset>
                    <legend>Template Definition</legend>
                    <div class="formrow block">
                        <div class="formcol">
                            <asp:Label ID="lblFileName" runat="server" AssociatedControlID="txtFileName" Text="Filename"></asp:Label>
                            <small class="formhint">The format to use for each bundle's filename</small>
                        </div>
                        <div class="formcol">
                            <asp:TextBox ID="txtFileName" runat="server" ValidationGroup="addtemplate" TextMode="MultiLine" Rows="6" CssClass="wide block"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="vldFileName" runat="server" 
                                ControlToValidate="txtFileName" Display="Dynamic" SetFocusOnError="true" ValidationGroup="addtemplate"
                                ErrorMessage="You must enter the format used to generate file names" CssClass="validationerror"></asp:RequiredFieldValidator>
                        </div>
                    </div>
                    <div class="formrow block">
                        <div class="formcol">
                            <asp:Label ID="lblFileStart" runat="server" AssociatedControlID="txtFileStart" Text="File Start"></asp:Label>
                            <small class="formhint">Text prepended to the start of each bundle</small>
                        </div>
                        <div class="formcol">
                            <asp:TextBox ID="txtFileStart" runat="server" ValidationGroup="addtemplate" TextMode="MultiLine" Rows="6" CssClass="wide block"></asp:TextBox>
                        </div>
                    </div>
                    <div class="formrow block">
                        <div class="formcol">
                            <asp:Label ID="lblFileEnd" runat="server" AssociatedControlID="txtFileEnd" Text="File End"></asp:Label>
                            <small class="formhint">Text to append to the end of each bundle</small>
                        </div>
                        <div class="formcol">
                            <asp:TextBox ID="txtFileEnd" runat="server" ValidationGroup="addtemplate" TextMode="MultiLine" Rows="6" CssClass="wide block"></asp:TextBox>
                        </div>
                    </div>
                    <div class="formrow block">
                        <div class="formcol">
                            <asp:Label ID="lblFileElement" runat="server" AssociatedControlID="txtFileElement" Text="Element"></asp:Label>
                            <small class="formhint">The format for each element</small>
                        </div>
                        <div class="formcol">
                        <asp:TextBox ID="txtFileElement" runat="server" ValidationGroup="addtemplate" TextMode="MultiLine" Rows="6" CssClass="wide block"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="vldFileElement" runat="server" 
                            ControlToValidate="txtFileElement" Display="Dynamic" SetFocusOnError="true" ValidationGroup="addtemplate"
                            ErrorMessage="You must enter the format for each element" CssClass="validationerror"></asp:RequiredFieldValidator>
                        </div>
                    </div>
                </fieldset>
                <div class="formrow block actions">
                    <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="uniformbutton" ValidationGroup="addtemplate"
                        OnClick="btnSave_Click" />
                </div>
            </div>
        </asp:View>
        <asp:View ID="pnlDeleteTemplate" runat="server">
            <div class="breadcrumbs">
                <asp:HyperLink ID="lnkNavHomeDelete" runat="server" NavigateUrl="~/Default.aspx">ResourceBlender</asp:HyperLink> &gt; <asp:HyperLink ID="lnkNavDeleteTemplates" runat="server" NavigateUrl="~/Templates.aspx">Templates</asp:HyperLink> &gt; Delete Template
            </div>
            <div class="niceform confirmation">
                <h1><asp:Label ID="lblConfirmDeletionHeading" runat="server" Text="Confirm Deletion" 
                        EnableViewState="False"></asp:Label></h1>
                <asp:Label ID="lblConfirmDelete" runat="server" 
                    Text="formatted text"></asp:Label>
                <br />
                <asp:Button ID="btnOk" runat="server" CommandName="confirmdelete" 
                    CssClass="uniformbutton" EnableViewState="False" onclick="btnOk_Click" 
                    Text="Delete Template" />
                <asp:Button ID="btnCancelDelete" runat="server" CommandName="canceldelete" 
                    CssClass="uniformbutton" EnableViewState="False" Text="Cancel" 
                    OnClick="btnCancelDelete_Click" />
            </div>
        </asp:View>
        <asp:View ID="viwError" runat="server">
            <div class="niceform error">
                <h1>Error</h1>
                <asp:Label ID="lblErrorDescription" runat="server" 
                    Text="formatted text"></asp:Label>
            </div>
        </asp:View>
    </asp:MultiView>
</asp:Content>